<?php
/**
 * Locations index controller
 * 
 * @author Konstantin Shamko <konstantin.shamko@gmail.com> 
 * @version 0.0.1
 * @copyright  Copyright (c) 2009 Konstantin Shamko
 * @package Locations Module
 * @subpackage Controller
 * @license  New BSD License
 *
 */
class locations_IndexController extends Bel_Controller{	

	/**
	 * Show regions by countries after AJAX request. 
	 * Provides JSON with regions. Used in countries smarty plugin 
	 *
	 */
	public function statebycountryAction() {
		$states = new Models_Locations_Regions();
		$country_id = $this->_request->getParam ( 'country_id' );
		
		$regions = $states->getRegionsByCountry ( $country_id );
		
		if ($regions) {
			$region ['regions'] = $regions->toArray ();
			$region ['current_region'] = $this->_request->getParam ( 'region_id' );
			echo Zend_Json::encode ( $region );
		}
		exit ();
	}	
}